package org.blame;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.resps.Tuple;

import java.util.List;

public class JedisDemoZSet {
    public static void main(String[] args) {
        JedisPool jedisPool=new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis=jedisPool.getResource()){
//            test1(jedis);
//            test2(jedis);
//            test3(jedis);
//            test4(jedis);
            test5(jedis);
        }
    }

    public static void test5(Jedis jedis) {
        jedis.flushAll();
        jedis.zadd("k", 12, "zhangsan");
        jedis.zadd("k", 13, "lisi");
        jedis.zadd("k", 14, "xiaohei");
        Long zrank = jedis.zrank("k", "xiaohei");
        System.out.println(zrank);
    }
        public static void test4(Jedis jedis){
        jedis.flushAll();
        jedis.zadd("k",12,"zhangsan");
        jedis.zadd("k",13,"lisi");
        jedis.zadd("k",14,"xiaohei");
        Double zscore = jedis.zscore("k", "zhangsan");
        System.out.println(zscore);
    }
    public static void test3(Jedis jedis){
        jedis.flushAll();
        jedis.zadd("k",12,"zhangsan");
        jedis.zadd("k",13,"lisi");
        jedis.zadd("k",14,"xiaohei");
        long zrem = jedis.zrem("k", "zhangsan", "lisi");
        System.out.println(zrem);
    }
    public static void test2(Jedis jedis){
        jedis.flushAll();
        jedis.zadd("k",12,"zhangsan");
        jedis.zadd("k",13,"lisi");
        jedis.zadd("k",14,"xiaohei");
        long k = jedis.zcard("k");
        System.out.println(k);
    }

    public static void test1(Jedis jedis){
        jedis.flushAll();
        jedis.zadd("k",12,"zhangsan");
        jedis.zadd("k",13,"lisi");
        jedis.zadd("k",14,"xiaohei");
        List<String> k = jedis.zrange("k", 0, -1);
        System.out.println(k);
        List<Tuple> k1 = jedis.zrangeWithScores("k", 0, -1);
        System.out.println(k1);
        double k2 = jedis.zrangeWithScores("k", 0, -1).get(0).getScore();
        String k3 = jedis.zrangeWithScores("k", 0, -1).get(0).getElement();
        System.out.println(k2);
        System.out.println(k3);
    }
}
